<template>
  <div class="goods">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索 -->
    <div style="margin-top: 15px">
      <el-input
        placeholder="请输入搜索内容"
        v-model="pageInfo.query"
        class="wd300 mt16"
      >
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <el-button type="primary" @click="goodsAddBtn">添加商品</el-button>
    </div>
    <!-- tab表格 -->

    <el-table border class="mt16" :data="goodsList">
      <el-table-column type="index" label="#"> </el-table-column>
      <el-table-column prop="goods_name" label="商品名称"> </el-table-column>
      <el-table-column prop="goods_price" label="商品价格"> </el-table-column>
      <el-table-column prop="goods_weight" label="商品重量"> </el-table-column>
      <el-table-column prop="upd_time" label="创建时间">
        <template slot-scope="scope">
          <div>
            {{ scope.row.upd_time | time }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template>
          <div>
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
            ></el-button>
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pagenum"
      :page-sizes="[10, 100, 500, 1000]"
      :page-size="pageInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: "goods",
  data() {
    return {
      //表格数据
      goodsList: [],
      //总条数
      total: 0,
      pageInfo: {
        query: "", //查询参数
        pagenum: 1, //当前页码
        pagesize: 10, //每页显示条数
      },
    };
  },
  computed: {},
  methods: {
    //获取商品列表
    async getGoodsList() {
      const res = await this.$http.getGoodsListApi(this.pageInfo);
      const { goods, total } = res;
      this.total = total;
      this.goodsList = goods;
      console.log(res, "获取商品列表");
    },
    //
    goodsAddBtn() {
      this.$router.push("/add");
    },

    //分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageInfo.pagesize = val;
      this.getGoodsList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageInfo.pagenum = val;
      this.getGoodsList();
    },
  },
  mounted() {},
  created() {
    this.getGoodsList();
  },
};
</script>
<style scoped lang="scss"></style>
